package com.fc.backingbeans.journal;

import javax.faces.bean.ViewScoped

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

import com.fc.backingbeans.AbstractDialog
import com.fc.entities.FoodJournal
import com.fc.service.UserDetailsService
import com.fc.service.FoodJournalService

/**
 * 
 * @author Ács Ádám
 *
 */
@Component("addFoodEntryDialog")
@ViewScoped
class AddFoodEntryDialog extends AbstractDialog {
	FoodJournal entry = new FoodJournal()
	@Autowired private FoodJournalService service 
	@Autowired private UserDetailsService userDetailsService
	
	void save() {
		entry.user = userDetailsService.getCurrentUser()
		service.create(entry)
		entry = new FoodJournal()
	}
	
	@Override
	String getDialogName() {
		"fc/journal/addFoodJournalEntry"
	}
}
